document.querySelector('#btn-register').addEventListener('click', async function() {
  const data = serialize(document.querySelector('.register-form'), {hash: true, empty: true})
  const {username, password} = data

  if (username == '' || password == '') {
    showToast('用户名和密码不能为空')
    return
  }

  if (username.length < 8 || username.length > 30 || password.length <6||password.length>30) {
    showToast('用户名长度为8-30，密码长度为6-30')
    return
  }

  try {
    const res = await axios.post('/register', data)
    // console.log(res)
    showToast(res.message)
  } catch (error) {
    // console.dir(error)
    showToast(error.response.data.message)
  }
  
})